import type { CommonResult, CommonPage } from '@/models/request'
import type { Resource, ResourcePageDto } from '@/models/resource'
import request from '@/utils/request'

export function fetchList(params: ResourcePageDto) {
  return request<CommonPage<Resource>>({
    url: '/resource/list',
    method: 'get',
    params: params,
  })
}

export function createResource(data: Resource) {
  return request<CommonResult>({
    url: '/resource/create',
    method: 'post',
    data: data,
  })
}

export function updateResource(id: number, data: Resource) {
  return request<CommonResult>({
    url: '/resource/update/' + id,
    method: 'post',
    data: data,
  })
}

export function deleteResource(id: number) {
  return request<CommonResult>({
    url: '/resource/delete/' + id,
    method: 'post',
  })
}

export function fetchAllResourceList() {
  return request<CommonResult<Resource[]>>({
    url: '/resource/listAll',
    method: 'get',
  })
}

export function resourceDetail(id: number) {
  return request<CommonResult>({
    url: '/resource/' + id,
    method: 'get',
  })
}
